package br.ueg.ezrides.visao.converter;

import org.zkoss.zk.ui.Component;
import org.zkoss.zkplus.databind.RadiogroupSelectedItemConverter;

@SuppressWarnings("serial")
public class BooleanRadiogroupConverter extends RadiogroupSelectedItemConverter {

	   @Override
	   public Object coerceToUi(Object val, Component component) {
	        if (val instanceof Boolean) {
	            Boolean bvalue = (Boolean) val;
	            String constanteName = bvalue.toString();
	            return super.coerceToUi(constanteName, component);
	        } else if (val == null){
	            return null;
	        } else {
	            throw new IllegalArgumentException("val Object must be an Boolean");
	        }
	    }

	    @Override
	    public Object coerceToBean(Object val, Component component) {
	        String booleanName = (String) super.coerceToBean(val, component);
	        return Boolean.parseBoolean(booleanName);
	    }
	    
}
